package com.qf.controller;


import com.qf.entity.*;
import com.qf.entity.custom.ShopPro;
import com.qf.entity.custom.UserEvaShopCustom;
import com.qf.mapper.UserModule;
import com.qf.service.AdminService;
import com.qf.service.UserModuleService;
import com.qf.service.impl.UserModuleServiceImpl;
import com.qf.tools.ResponseUtils;
import com.qf.tools.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author tanchangming
 */
@RestController
@RequestMapping(value = "/AdminController")
public class AdminController {
    @Autowired
    private UserModuleService userModuleService;
    @Autowired
    private UserModule userModule;
    @Autowired
    private AdminService adminService;


    /**
     * 管理员注册
     * @param admin
     * @return
     */
    @RequestMapping(value = "/register", method = RequestMethod.POST)
    public ResultEntity register(@RequestBody Admin admin) {
        String adminName = admin.getAdminName();
        String adminPwd = admin.getAdminPwd();
        if (adminName != null && adminName != "" && adminPwd != null && adminPwd != "") {
            return ResponseUtils.responseClinet(adminService.register(adminName, adminPwd));
        } else {
            return ResponseUtils.responseClinet(false);
        }
    }

    /**
     * @describtion 查看全部评价信息
     * @return
     */
    @RequestMapping(value = "/selectEvaShop",method = RequestMethod.POST)
    public ResultEntity  selectEvaShop(){
        List<UserEvaShopCustom> userEvaShopCustom = userModuleService.getUserEvaShopCustom();
        System.out.println(userEvaShopCustom);
        if (userEvaShopCustom != null){
            return ResultEntity.success(userEvaShopCustom);
        }else {
            return  ResponseUtils.responseClinet(false);
        }

    }

    /**
     * 商铺管理
     * @return
     */
    @RequestMapping(value = "/selectShop",method = RequestMethod.POST)
    public ResultEntity selectShop(){
        List<Shop> list = userModule.selectShop();
        if (list != null) {
        return ResultEntity.success(list);}
        else {
        return ResponseUtils.responseClinet(false);}
    }

    /**
     * 商铺管理详细信息
     * @return
     */
    @RequestMapping(value = "/selectShopPro" ,method = RequestMethod.POST)
    public ResultEntity selectShopPro(){
        List<ShopPro> list = userModule.selectShopPro();
        if (list != null){
            return ResultEntity.success(list);
        } else {
            return ResponseUtils.responseClinet(false);
        }
    }

    /**
     * @author tancahngming
     * @method 管理员信息
     * @param
     * @return
     */
    @RequestMapping(value = "/selectAdmin01",method = RequestMethod.POST)
    public ResultEntity selectAdmin01(@RequestBody Admin admin){

        Admin admin1 = userModule.selectAdmin01(admin.getAdminId());
        if (admin1 != null){

        return ResultEntity.success(admin1);
        } else {
            return ResponseUtils.responseClinet(false);
        }
    }


    /**
     * @author tanchangming
     * @method 管理员联系人
     * @param
     * @return
     */
    @RequestMapping(value = "/selectAdmin02",method = RequestMethod.POST)
    public ResultEntity selectAdmin02(@RequestBody Admin admin){

        Admin admin2 = userModule.selectAdmin02(admin.getAdminId());
            if(admin2 != null){

        return ResultEntity.success(admin2);
        }else {
            return ResponseUtils.responseClinet(false);
        }
    }


    /**
     * 用户管理
     * @return
     */
    @RequestMapping(value = "/selectUserAll",method = RequestMethod.POST)
    public ResultEntity selectUserAll(){
        List<User> list=userModule.selectUserAll();
        if(list != null){
        return ResultEntity.success(list);
    } else {
            return ResponseUtils.responseClinet(false);
        }
    }

    /**
     * 管理员首页
     * @return
     */
    @RequestMapping(value = "aa",method = RequestMethod.POST)
    public ResultEntity selectAll(){
        List<Integer> list = new ArrayList<>();
        Integer count1 = userModule.selectShopCount();
        list.add(count1);
        Integer count3 = userModule.selectUserCount();
        list.add(count3);
        Integer count2= userModule.selectShopCountTd();
        list.add(count2);
        Integer count4 = userModule.selectUserCountTd();
        list.add(count4);
        if(list!=null){
            return ResultEntity.success(list);
        } else {
            return ResponseUtils.responseClinet(false);
        }
    }


    /**
     * 删除商店
     * @param shop
     * @return
     */
    @RequestMapping(value = "/delShop",method = RequestMethod.POST)
    public ResultEntity delShop(Shop shop){

         if(userModuleService.deleteShop(shop.getShopId()) == true){
             return ResultEntity.success();
         } else {
             return ResponseUtils.responseClinet(false);
         }
    }

    /**
     * 删除用户
     * @param user
     * @return
     */
    @RequestMapping(value = "/delUser",method = RequestMethod.POST)
    public ResultEntity delUser(User user){

       if( userModuleService.deleteUser(user.getUserId()) == true){
           return ResultEntity.success();
       }else {
           return ResponseUtils.responseClinet(false);
       }
    }

    /**
     * 删除商品
     * @param product
     * @return
     */
    @RequestMapping(value = "/delProduct",method = RequestMethod.POST)
    public ResultEntity delProduct(Product product){
            if (userModuleService.deleteProduct(product.getProductId()) == true){
                return ResultEntity.success();
            } else {
                return ResponseUtils.responseClinet(false);
            }
    }

    /**
     * 删除评论
     * @param userEvaluation
     * @return
     */
    @RequestMapping(value = "/delEva",method = RequestMethod.POST)
    public ResultEntity delEva(UserEvaluation userEvaluation){
        int id = userEvaluation.getEvaluationId();
        if(userModuleService.deleteEva(id) == true){
            return ResultEntity.success();
        } else {
            return ResponseUtils.responseClinet(false);
        }
    }

   /* @RequestMapping(value = "/test")
    public void  test(){
        System.out.println("test");
    }*/

}
